package com.example.zuuldemo.api;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Component;

import java.net.URL;

/**
 * @author GuoAo
 * @className PreDemoFilter
 * @date 2025/3/5
 * @description TODO
 */
@Component
public class PreDemoFilter extends ZuulFilter {
    Logger log = org.slf4j.LoggerFactory.getLogger(PreDemoFilter.class);
    @Override
    public String filterType() {
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int filterOrder() {
        return FilterConstants.PRE_DECORATION_FILTER_ORDER + 1;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        RequestContext ctx = RequestContext.getCurrentContext();
        URL routeHost = ctx.getRouteHost();
        log.info("过滤器已执行！");
        System.out.println("routeHost:" + routeHost);
        return null;
    }
}
